package n08.first;

import java.util.Arrays;
import java.util.Comparator;

public class F01 {

	public static void main(String[] args) {
		Student[]a= {
				new Student("20240108", "张三", 21, 1.75),
				new Student("20240105", "李四", 19, 1.95),
				new Student("20240101", "王五", 20, 1.85),
		};
		//(1)按Student类Comparable默认的方法进行排序，默认按年龄排序
		System.out.println("按年龄排序~");
		Arrays.sort(a);
		for (Student student : a) {
			System.out.println(student);
		}
		//(2)对Student[]按身高进行排序，默认都是升序排列
		System.out.println("\n\n按身高默认升序排序~");
		Arrays.sort(a, new SortByHeight()); //升序排列
		for (Student student : a) {
			System.out.println(student);
		}
		//(3)对Student[]按身高进行排序，这里按降序排列
		System.out.println("\n\n按身高 降序 排序~");
		Arrays.sort(a, new SortByHeight().reversed()); //按降序排列
		for (Student student : a) {
			System.out.println(student);
		}
		//(4)利用匿名类对Student[]按学号升序排序
		System.out.println("\n\n按学号升序排列~");
		Arrays.sort(a, new Comparator<Student>() {
			@Override
			public int compare(Student o1, Student o2) { //排序的依据是学号
				return o1.getStudentId().compareTo(o2.getStudentId());
			}
		});
		for (Student student : a) {
			System.out.println(student);
		}
		
	}

}
